#include "stdafx.h"
#include "TinyCapture.h"
#include "ComPortConfig.h"
#include "afxdialogex.h"


IMPLEMENT_DYNAMIC(ComPortConfig, CDialog)

ComPortConfig::ComPortConfig(CWnd* pParent /*=NULL*/)
	: CDialog(ComPortConfig::IDD, pParent)
{
	mDeviceID = 0;
	mComPortID = 0;
}

ComPortConfig::~ComPortConfig()
{
}

void ComPortConfig::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_DEVICESEL, mDeviceSel);
	DDX_Control(pDX, IDC_COMPORTSEL, mComPortSel);
}


BEGIN_MESSAGE_MAP(ComPortConfig, CDialog)
	ON_BN_CLICKED(IDOK, &ComPortConfig::OnBnClickedOk)
END_MESSAGE_MAP()



BOOL ComPortConfig::OnInitDialog()
{
	CDialog::OnInitDialog();
	//set the config combobox value
	CString str;
	for (int i = 0; i < 9; i++)
	{
		str.Format(_T("Device %d"), i+1);
		mDeviceSel.AddString(str);
		str.Format(_T("ComPort %d"), i+1);
		mComPortSel.AddString(str);
	}
	int seledDeviceID = ( mDeviceID > 0 ? mDeviceID - 1 : 0);
	int seledComPortID = ( mComPortID > 0 ? mComPortID -1 : 0);
	mDeviceSel.SetCurSel(seledDeviceID);
	mComPortSel.SetCurSel(seledComPortID);

	return TRUE;   
}


void ComPortConfig::OnBnClickedOk()
{
	mDeviceID = mDeviceSel.GetCurSel() + 1;
	mComPortID = mComPortSel.GetCurSel() + 1;
	CDialog::OnOK();
}

int ComPortConfig::getSelDeviceID()
{
	return mDeviceID;
}

int ComPortConfig::getSelComPortID()
{
	return mComPortID;
}
